package com.authine.cloudpivot.web.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.web.api.bean.RoleAndUser;
import com.authine.cloudpivot.web.api.controller.base.BaseController;

import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.service.ProjectTeamService;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import com.authine.cloudpivot.web.api.vo.ExecutiveStaff;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "外企德科相关接口", tags = "组建团队接口")
@RestController
@RequestMapping("/api/projectTeam")
@Slf4j
@Validated
public class ProjectTeamController extends BaseController {

    @Autowired
    private ProjectTeamService  projectTeamService;
    /**
     * @Description : 获取组建团队中的执行成员列表
     * @param ： projectId
     * @author : Liun
     * @date : 2020/4/14
     */
    @ApiOperation(value = "获取组建团队中的执行成员列表" )
    @GetMapping("/getRoleAndUser")
    @ResponseBody
    public ResponseResult<?> getRoleAndUser(String projectId){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            List<RoleAndUser> lists=projectTeamService.getRoleAndUser(projectId);
            json.put("executiveStaffList",lists);
            json.put("message","获取执行成员列表成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "获取执行成员列表失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }


    /**
     * @Description : 批量更换某个城市下的督导
     * @param ： projectId
     * @author : Liun
     * @date : 2020/4/27
     */
    @ApiOperation(value = "批量更换某个城市下的督导" )
    @GetMapping("/setStoreDetail")
    @ResponseBody
    public ResponseResult<?> updateStoreDetail(String parentIdOld,String parentIdNew,String city){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            projectTeamService.updateStoreDetail(parentIdOld,parentIdNew,city);
            json.put("message","批量更换某个城市下的督导成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "批量更换某个城市下的督导失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }



    /**
     * @Description : 添加人员到客服和项目助理角色中去
     * @param ： projectId
     * @param ： role
     * @param ： member
     * @author : Liun
     * @date : 2020/7/22
     */
    @ApiOperation(value = "添加人员到客服和项目助理角色中去" )
    @GetMapping("/createCustomerAndAssistant")
    @ResponseBody
    public ResponseResult<?> createCustomerAndAssistant (String projectId,String role,String member){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            projectTeamService.createCustomerAndAssistant(projectId,role,member);
            json.put("message","组建团队添加角色到组织架构成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "组建团队添加角色到组织架构失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }




    /**
     * @Description : 修改项目成员
     * @param ： projectId
     * @param ： role
     * @param ： member
     * @author : Liun
     * @date : 2020/7/29
     */
    public ResponseResult<?> updateCustomerAndAssistant (String projectId,String role,String memberOld,String memberNew){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            json.put("message","组建团队添加角色到组织架构成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "组建团队添加角色到组织架构失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }









}
